<!DOCTYPE HTML>
<html>
  <head>
    <title>My JSP 'eval.jsp' starting page</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
	<style type="text/css">
		body{font-size: 12px;}
		textarea {width:99%;height:180px;margin: 4px;}
		label {cursor: pointer;}
	</style>
  </head>
  
  <body>
    <textarea id="tm-source">&lt;label&gt;&lt;input type="radio" name="type" value="2"&gt;双引号转单引号&lt;/label&gt;
&lt;label&gt;&lt;input type="radio" name="type" value="2"&gt;双引号转单引号&lt;/label&gt;
&lt;label&gt;&lt;input type="radio" name="type" value="2"&gt;双引号转单引号&lt;/label&gt;
&lt;label&gt;&lt;input type="radio" name="type" value="2"&gt;双引号转单引号&lt;/label&gt;
dfsd
s dsfdf 
   dfsdf
    </textarea>
    <label><input type="radio" name="type" value="2">双引号转单引号</label>
    <label><input type="radio" name="type" value="1" checked="checked">单引号转双引号</label>
    <label><input type="button" onclick="tm_transfter()" value="开始转换"></label>
    <textarea id="tm-target"></textarea>
    <textarea id="tm-result"></textarea>
    <script type="text/javascript">
    	function tm_transfter(){
    		var source = $.trim($("#tm-source").val().replace(/(\n)*$/,""));
    		var checkVal = $("input[type='radio']:checked").val();
	    	var result = "$('#xxxx').append(";
    		if(checkVal==2){
    			$("#tm-target").val(source.replace(/"/g,"'"));
    			var arr = $("#tm-target").val().match(/^(.*\n*)$/igm);
	    		for(var i=0;i<arr.length;i++){
	    			result += '"'+arr[i]+'"+\n';
	    		}
	    		$("#tm-result").val(result.substring(0,result.length-2)+");");
    		}
    		if(checkVal==1){
    			$("#tm-target").val(source.replace(/'/g,'\"'));
    			$("#tm-target").val(source.replace(/"/g,"\\\""));
	    		var arr = $("#tm-target").val().match(/^(.*\n*)$/igm);
	    		for(var i=0;i<arr.length;i++){
	    			result+='"'+arr[i].replace(/\s*/,'')+'"'+"+"+'\n';
	    		}
	    		$("#tm-result").val(result.substring(0,result.length-2)+");");
    		}
    	}
    </script>
  </body>
</html>
